package com.sctvcloud.qingchuan.ui.activities;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.jiongbull.jlog.JLog;
import com.luck.picture.lib.PictureExternalPreviewActivity;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.ruihang.generalibrary.utils.ListUtils;
import com.sctvcloud.qingchuan.R;
import com.sctvcloud.qingchuan.application.Cache;
import com.sctvcloud.qingchuan.application.Constances;
import com.sctvcloud.qingchuan.base.BaseActivity;
import com.sctvcloud.qingchuan.beans.PoliticsItem;
import com.sctvcloud.qingchuan.beans.PoliticsProcessBean;
import com.sctvcloud.qingchuan.beans.PoliticsReplyDotBean;
import com.sctvcloud.qingchuan.http.AbsNetCallBack;
import com.sctvcloud.qingchuan.http.NetUtils;
import com.sctvcloud.qingchuan.ui.adapter.PoliticsDetailHandleAdapter;
import com.sctvcloud.qingchuan.ui.adapter.PoliticsItemImgAdapter;
import com.sctvcloud.qingchuan.ui.adapter.holder.PoliticsReplyHolder;
import com.sctvcloud.qingchuan.ui.adapter.holder.PoliticsUserReplyHolder;
import com.sctvcloud.qingchuan.ui.dialog.PoliticsEvaluateDiaFragment;
import com.sctvcloud.qingchuan.ui.dialog.PoliticsReplyDiaFragment;
import com.sctvcloud.qingchuan.ui.utils.DataUtils;
import com.sctvcloud.qingchuan.ui.utils.SkipUtil;
import com.sctvcloud.qingchuan.ui.utils.TitleUtils;
import com.sctvcloud.qingchuan.ui.utils.UIUtils;
import com.sctvcloud.qingchuan.utils.UserManager;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 问政详情
 */
public class PoliticsDetailActivity extends BaseActivity implements PoliticsReplyHolder.OnLoadMoreReplyClickListener, PoliticsUserReplyHolder.OnReplyClickListener {
    @BindView(R.id.item_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_content)
    protected CustomFontTextView content;
    @BindView(R.id.item_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_read_count)
    protected CustomFontTextView readCount;

    @BindView(R.id.item_image_layout)
    protected LinearLayout imageLayout;
    @BindView(R.id.item_only_img)
    protected ImageView itemOnlyImg;
    @BindView(R.id.item_img_list)
    protected RecyclerView itemImgListView;

    @BindView(R.id.item_video_layout)
    protected FrameLayout videoLayout;
    @BindView(R.id.item_video_img)
    protected ImageView videoImage;


    @BindView(R.id.status_1)
    protected ImageView status_1;
    @BindView(R.id.line_1)
    protected View line_1;
    @BindView(R.id.status_2)
    protected ImageView status_2;
    @BindView(R.id.line_2)
    protected View line_2;
    @BindView(R.id.status_3)
    protected ImageView status_3;
    @BindView(R.id.line_3)
    protected View line_3;
    @BindView(R.id.status_4)
    protected ImageView status_4;

    @BindView(R.id.status_one)
    protected CustomFontTextView status_one;
    @BindView(R.id.status_one_time)
    protected CustomFontTextView status_one_time;
    @BindView(R.id.status_two)
    protected CustomFontTextView status_two;
    @BindView(R.id.status_two_time)
    protected CustomFontTextView status_two_time;
    @BindView(R.id.status_three)
    protected CustomFontTextView status_three;
    @BindView(R.id.status_three_time)
    protected CustomFontTextView status_three_time;
    @BindView(R.id.status_four)
    protected CustomFontTextView status_four;
    @BindView(R.id.status_four_time)
    protected CustomFontTextView status_four_time;

    @BindView(R.id.politics_reply_layout)
    protected LinearLayout politics_reply_layout;
    @BindView(R.id.divider1)
    protected View divider1;
    @BindView(R.id.item_reply_list)
    protected RecyclerView replyListView;

    @BindView(R.id.politics_score_layout)
    protected LinearLayout politics_score_layout;
    @BindView(R.id.divider2)
    protected View divider2;
    @BindView(R.id.politics_score)
    protected RatingBar politics_score;


    public static final int LOAD_MORE_REPLY = 1;
    protected PoliticsReplyDiaFragment replyDiaFragment;
    protected PoliticsEvaluateDiaFragment evaluateDiaFragment;

    public static final String POLITICS_ID = "politics_id";
    private PoliticsItemImgAdapter imgAdapter;
    private PoliticsDetailHandleAdapter handleAdapter;
    private GridLayoutManager mgr;
    private PoliticsItem politicsDetail;
    private long politicsId;
    private int departmentType = 1;
    private int backReplyNumber = 5;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new TitleUtils(this).useAndSetTxTitle("回音壁详情");
        mgr = new GridLayoutManager(this, 3);

        politicsId = getIntent().getLongExtra(POLITICS_ID, 0);
        initView();
        getData();
    }

    @Override
    protected void onDestroy() {
        Cache.getInstance().setPcCondition(null);
        super.onDestroy();
    }

    @Override
    protected void initInject() {
        setContentView(R.layout.activity_politics_detail);
        ButterKnife.bind(this);
    }


    private void initView() {
        replyListView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        replyListView.setItemAnimator(new DefaultItemAnimator());
        handleAdapter = new PoliticsDetailHandleAdapter(this, null, this, this);
        replyListView.setAdapter(handleAdapter);
    }

    private void getData() {
        if (politicsId > 0) {
            showProgress("正在加载...");
            String userId = "";
            if (null != UserManager.getInstance().getUser()) {
                userId = UserManager.getInstance().getUser().getUserId();
            }
            NetUtils.getNetAdapter().toGetPoliticsInfoString(getOwnerName(), Constances.TENANT_ID, politicsId, departmentType, backReplyNumber, userId, new AbsNetCallBack<String>(String.class) {
                @Override
                public void onSucStr(String news) {
                    if (!TextUtils.isEmpty(news)) {
                        try {
                            politicsDetail = gson.fromJson(news, PoliticsItem.class);
                            initData();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        onError(null, "数据异常");
                    }
                }

                @Override
                public void onError(Throwable ex, String errorMsg) {
                    toast(errorMsg);
                }


                @Override
                public void onEnd() {
                    closeProgress();
                }
            });
        }

    }

    private void initData() {
        if (politicsDetail != null) {
            List<PoliticsReplyDotBean> l = new ArrayList<>();
            for (int k = 0; k < 2; k++) {
                PoliticsReplyDotBean bean = new PoliticsReplyDotBean();
                bean.setAvatar("");
                bean.setNickName(k + "旺苍融媒号");
                bean.setContent(k + "第一个融媒号回复第一个融媒号回复第一个融媒号回复第一个融媒号回复第一个融媒号回复第一个融媒号回复");
                bean.setCreateTime("2019-12-26 10:10:10");
                l.add(bean);

                List<PoliticsReplyDotBean> l_1 = new ArrayList<>();
                PoliticsReplyDotBean bean1 = new PoliticsReplyDotBean();
                bean1.setContent(k + "第一个融媒号的追问1");
                bean1.setCreateTime("2019-12-26");
                l_1.add(bean1);
                List<PoliticsReplyDotBean> al = new ArrayList<>();
                PoliticsReplyDotBean bean1_2 = new PoliticsReplyDotBean();
                bean1_2.setContent(k + "第一个融媒号的追问1回复");
                bean1_2.setCreateTime("2019-12-26");
                al.add(bean1_2);
                l_1.get(0).setInteractionReplyDtoList(al);

                PoliticsReplyDotBean bean2 = new PoliticsReplyDotBean();
                bean2.setContent(k + "第一个融媒号的追问2");
                bean2.setCreateTime("2019-12-26");
                l_1.add(bean2);
                List<PoliticsReplyDotBean> al2 = new ArrayList<>();
                PoliticsReplyDotBean bean2_2 = new PoliticsReplyDotBean();
                bean2_2.setContent(k + "第一个融媒号的追问2回复1");
                bean2_2.setCreateTime("2019-12-26");
                al2.add(bean2_2);

                PoliticsReplyDotBean bean2_21 = new PoliticsReplyDotBean();
                bean2_21.setContent(k + "第一个融媒号的追问2回复2");
                bean2_21.setCreateTime("2019-12-26");
                al2.add(bean2_21);
                l_1.get(1).setInteractionReplyDtoList(al2);

                PoliticsReplyDotBean bean3 = new PoliticsReplyDotBean();
                bean3.setContent(k + "第一个融媒号的追问3");
                bean3.setCreateTime("2019-12-26");
                l_1.add(bean3);
                List<PoliticsReplyDotBean> al3 = new ArrayList<>();
                PoliticsReplyDotBean bean3_2 = new PoliticsReplyDotBean();
                bean3_2.setContent(k + "第一个融媒号的追问3回复");
                bean3_2.setCreateTime("2019-12-26");
                al3.add(bean3_2);
                l_1.get(2).setInteractionReplyDtoList(al3);
                l.get(k).setInteractionReplyDtoList(l_1);
            }


            List<PoliticsReplyDotBean> list = politicsDetail.getInteractionReplyDtoList();
            List<PoliticsReplyDotBean> listNew = new ArrayList<>();
            if (ListUtils.isListValued(list)) {
                for (int i = 0; i < list.size(); i++) {
                    PoliticsReplyDotBean reply = list.get(i);
                    List<PoliticsReplyDotBean> replyList = DataUtils.handlePoliticsReply(reply.getInteractionReplyDtoList());
                    reply.setInteractionReplyDtoList(replyList);
                    reply.setPosition(i);
                    listNew.add(reply);
                }
            }
            if (ListUtils.isListValued(listNew)) {
                politics_reply_layout.setVisibility(View.VISIBLE);
                divider1.setVisibility(View.VISIBLE);
                handleAdapter.setData(listNew);
            } else {
                politics_reply_layout.setVisibility(View.GONE);
                divider1.setVisibility(View.GONE);
            }

            if (politicsDetail.getScore() > 0) {
                politics_score_layout.setVisibility(View.VISIBLE);
                divider2.setVisibility(View.VISIBLE);
                politics_score.setRating(politicsDetail.getScore());
            } else if (ListUtils.isListValued(list)) {
                politics_score_layout.setVisibility(View.VISIBLE);
                divider2.setVisibility(View.VISIBLE);
                politics_score.setRating(0);
            } else {
                politics_score_layout.setVisibility(View.GONE);
                divider2.setVisibility(View.GONE);
            }
            String clickCount = UIUtils.getPoliticsListNumber(politicsDetail.getHitCount());
            readCount.setText(clickCount + "阅读");
            title.setText(politicsDetail.getTitle());
            content.setText(politicsDetail.getContent());
            time.setText(DateUtils.formatDate(DateUtils.getDataDate(politicsDetail), ""));

            if (ListUtils.isListValued(politicsDetail.getInteractioninfoImageList())) {
                imageLayout.setVisibility(View.VISIBLE);
                if (politicsDetail.getInteractioninfoImageList().size() == 1) {
                    final String path = politicsDetail.getInteractioninfoImageList().get(0).getImagePath();
                    itemOnlyImg.setVisibility(View.VISIBLE);
                    itemImgListView.setVisibility(View.GONE);
                    initImgView(path);
                    itemOnlyImg.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            List<LocalMedia> images = new ArrayList<LocalMedia>();

                            LocalMedia localMedia = new LocalMedia();
                            localMedia.setPath(path);
                            images.add(localMedia);

                            Intent intent = new Intent(PoliticsDetailActivity.this, PictureExternalPreviewActivity.class);
                            intent.putExtra("type", 1);
                            intent.putExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST, (Serializable) images);
                            intent.putExtra(PictureConfig.EXTRA_POSITION, 0);
                            PoliticsDetailActivity.this.startActivity(intent);
                        }
                    });
                } else {
                    itemOnlyImg.setVisibility(View.GONE);
                    itemImgListView.setVisibility(View.VISIBLE);
                    itemImgListView.setLayoutManager(mgr);
                    imgAdapter = new PoliticsItemImgAdapter(PoliticsDetailActivity.this, politicsDetail.getInteractioninfoImageList());
                    itemImgListView.setAdapter(imgAdapter);

                }
            } else {
                imageLayout.setVisibility(View.GONE);
            }

            if (ListUtils.isListValued(politicsDetail.getInteractioninfoVideoList())) {
                final String path = politicsDetail.getInteractioninfoVideoList().get(0).getLogo();
                final String videoUrl = politicsDetail.getInteractioninfoVideoList().get(0).getUrl();
                videoLayout.setVisibility(View.VISIBLE);
                initVideoImgView(path);
                videoLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SkipUtil.skipToVideoPlayWithCover(PoliticsDetailActivity.this, videoUrl, 0, 0, path);
                    }
                });

            } else {
                videoLayout.setVisibility(View.GONE);
            }
            initProcessData();
        }

    }


    private void initImgView(final String path) {
        Glide.with(this)
                .load(path)
                .asBitmap()//强制Glide返回一个Bitmap对象
                .centerCrop()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
                        int width = bitmap.getWidth();
                        int height = bitmap.getHeight();
                        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) itemOnlyImg.getLayoutParams();
                        if (height > width) {
                            if (height > UIUtils.dip2px(PoliticsDetailActivity.this, 240)) {
                                params.width = UIUtils.dip2px(PoliticsDetailActivity.this, 140);
                                params.height = UIUtils.dip2px(PoliticsDetailActivity.this, 240);
                            } else {
                                params.height =  height ;
                                params.width =  width ;
                            }
                        } else if (height < width) {
                            if (width > UIUtils.dip2px(PoliticsDetailActivity.this, 240)) {
                                params.height = UIUtils.dip2px(PoliticsDetailActivity.this, 140);
                                params.width = UIUtils.dip2px(PoliticsDetailActivity.this, 240);
                            } else {
                                params.height =  height ;
                                params.width =  width ;
                            }
                        } else {
                            JLog.e("-----onResourceReady---width = " + width + "---------height = " + height);
                            if (height > UIUtils.dip2px(PoliticsDetailActivity.this, 140)) {
                                params.height = UIUtils.dip2px(PoliticsDetailActivity.this, 140);
                                params.width = UIUtils.dip2px(PoliticsDetailActivity.this, 140);
                            } else {
                                params.height =  height ;
                                params.width =  width ;
                            }
                        }
                        itemOnlyImg.setLayoutParams(params);
//                        itemOnlyImg.setImageBitmap(bitmap);
                        Glide.with(PoliticsDetailActivity.this)
                                .load(path)
                                .error(com.luck.picture.lib.R.drawable.icon_def_1_1)
                                .into(itemOnlyImg);
                    }
                });
    }

    private void initVideoImgView(final String path) {
        Glide.with(this)
                .load(path)
                .asBitmap()//强制Glide返回一个Bitmap对象
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
                        int width = bitmap.getWidth();
                        int height = bitmap.getHeight();
                        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) videoImage.getLayoutParams();
                        if (height > width) {
                            if (width > UIUtils.dip2px(PoliticsDetailActivity.this, 100)) {
                                params.width = UIUtils.dip2px(PoliticsDetailActivity.this, 100);
                                params.height = UIUtils.dip2px(PoliticsDetailActivity.this, 178);
                            } else {
                                params.height =  height ;
                                params.width =  width ;
                            }
                        } else if (height < width) {
                            if (height > UIUtils.dip2px(PoliticsDetailActivity.this, 100)) {
                                params.height = UIUtils.dip2px(PoliticsDetailActivity.this, 100);
                                params.width = UIUtils.dip2px(PoliticsDetailActivity.this, 178);
                            } else {
                                params.height =  height ;
                                params.width =  width ;
                            }
                        } else {
                            if (height > UIUtils.dip2px(PoliticsDetailActivity.this, 100)) {
                                params.height = UIUtils.dip2px(PoliticsDetailActivity.this, 100);
                                params.width = UIUtils.dip2px(PoliticsDetailActivity.this, 100);
                            } else {
                                params.height =  height ;
                                params.width =  width ;
                            }
                        }
                        videoImage.setLayoutParams(params);
                        Glide.with(PoliticsDetailActivity.this)
                                .load(path)
                                .centerCrop().error(com.luck.picture.lib.R.drawable.icon_def_1_1)
                                .into(videoImage);
                    }
                });

    }

    /**
     * 加载处理进度
     */
    private void initProcessData() {
        if (politicsDetail != null) {
            if (ListUtils.isListValued(politicsDetail.getInteractionprocessList())) {
                PoliticsProcessBean process2 = null;
                PoliticsProcessBean process3 = null;
                for (int i = 0; i < politicsDetail.getInteractionprocessList().size(); i++) {
                    if (politicsDetail.getInteractionprocessList().get(i).getOperationStatus() == 3 || politicsDetail.getInteractionprocessList().get(i).getOperationStatus() == 8) {
                        process2 = politicsDetail.getInteractionprocessList().get(i);
                    } else if (politicsDetail.getInteractionprocessList().get(i).getOperationStatus() == 4) {
                        process3 = politicsDetail.getInteractionprocessList().get(i);
                    }
                }
                PoliticsProcessBean process = politicsDetail.getInteractionprocessList().get(politicsDetail.getInteractionprocessList().size() - 1);
                if (null != process && process.getOperationStatus() == 1) {
                    status_1.setImageResource(R.mipmap.icon_in);
                    status_2.setImageResource(R.mipmap.icon_un);
                    status_3.setImageResource(R.mipmap.icon_un);
                    status_4.setImageResource(R.mipmap.icon_un);
                    status_one.setTextColor(getResources().getColor(R.color.colorHomeText));
                    status_one_time.setTextColor(getResources().getColor(R.color.colorHomeText));
                    if (null != politicsDetail) {
                        status_one_time.setText(DateUtils.formatDate(DateUtils.getDataDate(politicsDetail), ""));
                    }
                } else if (null != process && (process.getOperationStatus() == 3 || process.getOperationStatus() == 8)) {
                    status_1.setImageResource(R.mipmap.icon_pro);
                    status_2.setImageResource(R.mipmap.icon_in);
                    status_3.setImageResource(R.mipmap.icon_un);
                    status_4.setImageResource(R.mipmap.icon_un);
                    line_1.setBackground(getResources().getDrawable(R.drawable.line_1));
                    status_one.setTextColor(getResources().getColor(R.color.color_989898));
                    status_one_time.setTextColor(getResources().getColor(R.color.color_989898));
                    if (null != politicsDetail) {
                        status_one_time.setText(DateUtils.formatDate(DateUtils.getDataDate(politicsDetail), ""));
                    }
                    status_two.setTextColor(getResources().getColor(R.color.colorHomeText));
                    status_two_time.setTextColor(getResources().getColor(R.color.colorHomeText));
                    if (null != process2) {
                        status_two_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process2), ""));
                    }

                } else if (null != process && process.getOperationStatus() == 4) {
                    if (politicsDetail.getScore() == 0) {
                        status_1.setImageResource(R.mipmap.icon_pro);
                        status_2.setImageResource(R.mipmap.icon_pro);
                        status_3.setImageResource(R.mipmap.icon_in);
                        status_4.setImageResource(R.mipmap.icon_un);
                        line_1.setBackground(getResources().getDrawable(R.drawable.line_1));
                        line_2.setBackground(getResources().getDrawable(R.drawable.line_1));
                        status_one.setTextColor(getResources().getColor(R.color.color_989898));
                        status_one_time.setTextColor(getResources().getColor(R.color.color_989898));
                        if (null != politicsDetail) {
                            status_one_time.setText(DateUtils.formatDate(DateUtils.getDataDate(politicsDetail), ""));
                        }
                        status_two.setTextColor(getResources().getColor(R.color.color_989898));
                        status_two_time.setTextColor(getResources().getColor(R.color.color_989898));
                        if (null != process2) {
                            status_two_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process2), ""));
                        }
                        status_three.setTextColor(getResources().getColor(R.color.colorHomeText));
                        status_three_time.setTextColor(getResources().getColor(R.color.colorHomeText));
                        if (null != process3) {
                            status_three_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process3), ""));
                            if (null == process2) {
                                status_two_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process3), ""));
                            }
                        }

                    } else {
                        status_1.setImageResource(R.mipmap.icon_pro);
                        status_2.setImageResource(R.mipmap.icon_pro);
                        status_3.setImageResource(R.mipmap.icon_pro);
                        status_4.setImageResource(R.mipmap.icon_in);
                        line_1.setBackground(getResources().getDrawable(R.drawable.line_1));
                        line_2.setBackground(getResources().getDrawable(R.drawable.line_1));
                        line_3.setBackground(getResources().getDrawable(R.drawable.line_1));
                        status_one.setTextColor(getResources().getColor(R.color.color_989898));
                        status_one_time.setTextColor(getResources().getColor(R.color.color_989898));
                        if (null != politicsDetail) {
                            status_one_time.setText(DateUtils.formatDate(DateUtils.getDataDate(politicsDetail), ""));
                        }
                        status_two.setTextColor(getResources().getColor(R.color.color_989898));
                        status_two_time.setTextColor(getResources().getColor(R.color.color_989898));
                        if (null != process2) {
                            status_two_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process2), ""));
                        }
                        status_three.setTextColor(getResources().getColor(R.color.color_989898));
                        status_three_time.setTextColor(getResources().getColor(R.color.color_989898));
                        if (null != process3) {
                            status_three_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process3), ""));
                            if (null == process2) {
                                status_two_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process3), ""));
                            }
                        }
                        status_four.setTextColor(getResources().getColor(R.color.colorHomeText));
                        status_four_time.setTextColor(getResources().getColor(R.color.colorHomeText));
                        status_four_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process), ""));
                    }
                } else {
                    status_1.setImageResource(R.mipmap.icon_pro);
                    status_2.setImageResource(R.mipmap.icon_pro);
                    status_3.setImageResource(R.mipmap.icon_in);
                    status_4.setImageResource(R.mipmap.icon_un);
                    line_1.setBackground(getResources().getDrawable(R.drawable.line_1));
                    line_2.setBackground(getResources().getDrawable(R.drawable.line_1));
                    status_one.setTextColor(getResources().getColor(R.color.color_989898));
                    status_one_time.setTextColor(getResources().getColor(R.color.color_989898));
                    if (null != politicsDetail) {
                        status_one_time.setText(DateUtils.formatDate(DateUtils.getDataDate(politicsDetail), ""));
                    }
                    status_two.setTextColor(getResources().getColor(R.color.color_989898));
                    status_two_time.setTextColor(getResources().getColor(R.color.color_989898));
                    if (null != process2) {
                        status_two_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process2), ""));
                    }
                    status_three.setTextColor(getResources().getColor(R.color.colorHomeText));
                    status_three_time.setTextColor(getResources().getColor(R.color.colorHomeText));
                    if (null != process3) {
                        status_three_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process3), ""));
                        if (null == process2) {
                            status_two_time.setText(DateUtils.formatDate(DateUtils.getDataDate(process3), ""));
                        }
                    }
                }
            }

        }

    }

    @OnClick({R.id.score_layout})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.score_layout:
                if (politicsDetail.getScore() == 0) {
                    toEvaluate();
                } else {
                    toast("已经进行了评分，不能重复评分");
                }

                break;
        }
    }

    /**
     * 进行评分设置
     */
    private void toEvaluate() {
        if (UserManager.getInstance().isLogin()) {
            String userId = UserManager.getInstance().getUser().getUserId();
            long id = Long.parseLong(userId);
            if (id == politicsDetail.getUserId()) {
                FragmentManager fm = getSupportFragmentManager();
//        if (commentDiaFragment == null) {
                evaluateDiaFragment = new PoliticsEvaluateDiaFragment();
                evaluateDiaFragment.setSendScoreListener(new PoliticsEvaluateDiaFragment.SendScoreListener() {
                    @Override
                    public void onEvaluateSendSuccess() {
                        toast("评价成功");
                        getData();
                    }
                });

                evaluateDiaFragment.setPoliticsInfo(politicsDetail.getId());
                evaluateDiaFragment.show(fm, "dia_politics_reply");
                fm.executePendingTransactions();
            } else {
                toast("您不是提问用户，不能评分");
            }
        } else {
            toLogin();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == LOAD_MORE_REPLY) {
                getData();
            }
        }
    }


    @Override
    public void OnLoadMoreReply(PoliticsReplyDotBean t) {
        //TODO 查看更多回复
        Intent intent = new Intent(this, PoliticsMoreReplyActivity.class);
        intent.putExtra(PoliticsMoreReplyActivity.POLITICS_ID, politicsDetail.getId());
        intent.putExtra(PoliticsMoreReplyActivity.POLITICS_REPLY_ID, t.getId());
        intent.putExtra(PoliticsMoreReplyActivity.POLITICS_USER_ID, politicsDetail.getUserId());
        startActivityForResult(intent, LOAD_MORE_REPLY);
    }

    @Override
    public void OnReplyClick(PoliticsReplyDotBean t) {
        //TODO 点击回复
        if (UserManager.getInstance().isLogin()) {
            String userId = UserManager.getInstance().getUser().getUserId();
            long id = Long.parseLong(userId);
            if (id == politicsDetail.getUserId()) {
                FragmentManager fm = getSupportFragmentManager();
//        if (commentDiaFragment == null) {
                replyDiaFragment = new PoliticsReplyDiaFragment();
                replyDiaFragment.setSendComment(new PoliticsReplyDiaFragment.SendComment() {
                    @Override
                    public boolean onCommentSendPrepare(int mode) {
                        return false;
                    }

                    @Override
                    public void onCommentSendSuccess(int mode) {
                        toast("发送成功");
                        getData();
                    }

                    @Override
                    public void onCommentSendFinish(int mode, boolean isNetSuc) {

                    }
                });

                replyDiaFragment.setReplyInfo(politicsDetail.getId(), t.getId());
                replyDiaFragment.show(fm, "dia_politics_reply");
                fm.executePendingTransactions();
            } else {
                toast("您不是提问用户，不能追问");
            }
        } else {
            toLogin();
        }
    }
}
